import sys
import os

ROOT_DIRS = os.path.dirname(os.path.abspath(__file__))

def install():
    install_requires = ['click-6.7.tar.gz']
    if sys.version_info < (2, 7):
        install_requires.append('ordereddict-1.1.tar.gz')
    if sys.version_info < (2, 7, 9):
        install_requires.append('backports.ssl_match_hostname-3.5.0.1.tar.gz')
    if sys.version_info < (3, 4):
        install_requires.append('singledispatch-3.4.0.3.tar.gz')
        install_requires.append('certifi-2017.7.27.1.tar.gz')
    if sys.version_info < (3, 5):
        install_requires.append('backports_abc-0.5.tar.gz')
    for package in install_requires:
        i = package.find(".tar.gz")
        dir_name = package[:i]
        os.chdir(os.path.join(ROOT_DIRS, "dep"))
        if not os.path.exists(dir_name):
            os.system("tar xzf %s" % package)
        print (os.path.join(ROOT_DIRS, "dep", dir_name))
        os.chdir(os.path.join(ROOT_DIRS, "dep", dir_name))
        os.system("python setup.py install")

if __name__ == '__main__':
    install()
